package com.taomu.app.zongchouhuli.moudle.mine.activity;

import android.graphics.Bitmap;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.taomu.app.zongchouhuli.R;
import com.taomu.app.zongchouhuli.framework.BaseActivity;
import com.taomu.app.zongchouhuli.framework.BasePresenter;
import com.taomu.app.zongchouhuli.http.res.ResUserInfoEntity;
import com.taomu.app.zongchouhuli.utils.ParseUtil;
import com.taomu.app.zongchouhuli.utils.StorageHelper;
import com.taomu.app.zongchouhuli.utils.zxing.QrUtils;

/**
 * 推广码
 */
public class UserSpreadCodeActivity extends BaseActivity {

    private ImageView mBackIm;

    private ImageView mQrCodeIm;

    private TextView mInvitCodeTv;

    @Override
    protected int getContentLayout() {
        return R.layout.activity_spread_code;
    }

    @Override
    protected void initView() {
        mBackIm = findViewById(R.id.spread_code_back_im);
        mQrCodeIm = findViewById(R.id.spread_code_im);
        mInvitCodeTv = findViewById(R.id.spread_code_tv);
    }

    @Override
    protected void initData() {
        mInvitCodeTv.setText("推广码："+ParseUtil.parseObject(StorageHelper.getAccountInfo(), ResUserInfoEntity.class).getInvite_code());
        mBackIm.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        //todo:获取下载链接
        String url = "";
        if(!TextUtils.isEmpty(StorageHelper.getHttpNewDownload())){
            url = StorageHelper.getHttpNewDownload();
        }else{
            url = "https://www.pgyer.com/kLoG";
        }
        Bitmap barcodebit = QrUtils.createQr(url,300);
        if(barcodebit != null){
            mQrCodeIm.setImageBitmap(barcodebit);
        }
    }

    @Override
    protected void initEvent() {

    }

    @Override
    protected BasePresenter createPresenter() {
        return null;
    }
}
